<?php if (!defined("MAIN_DIR")) die("<h1>Access denied</h1>");

// переводит url в транслит
function translitURL($str) 
{
    $tr = array(
        "А"=>"a","Б"=>"b","В"=>"v","Г"=>"g",
        "Д"=>"d","Е"=>"e","Ж"=>"j","З"=>"z","И"=>"i",
        "Й"=>"y","К"=>"k","Л"=>"l","М"=>"m","Н"=>"n",
        "О"=>"o","П"=>"p","Р"=>"r","С"=>"s","Т"=>"t",
        "У"=>"u","Ф"=>"f","Х"=>"h","Ц"=>"ts","Ч"=>"ch",
        "Ш"=>"sh","Щ"=>"sch","Ъ"=>"","Ы"=>"yi","Ь"=>"",
        "Э"=>"e","Ю"=>"yu","Я"=>"ya","а"=>"a","б"=>"b",
        "в"=>"v","г"=>"g","д"=>"d","е"=>"e","ж"=>"j",
        "з"=>"z","и"=>"i","й"=>"y","к"=>"k","л"=>"l",
        "м"=>"m","н"=>"n","о"=>"o","п"=>"p","р"=>"r",
        "с"=>"s","т"=>"t","у"=>"u","ф"=>"f","х"=>"h",
        "ц"=>"ts","ч"=>"ch","ш"=>"sh","щ"=>"sch","ъ"=>"y",
        "ы"=>"yi","ь"=>"","э"=>"e","ю"=>"yu","я"=>"ya", 
        " "=> "_", "."=> "", "/"=> "_"
    );
    return strtr($str,$tr);
}

// function wordEnding - returns word $ending depending on $count $with or without $count
function wordEnding($count,$ending1,$ending2,$ending3,$with=true,$one=true)
{
	if ($count == 1)
		return $one ? $ending1 : "1 $ending1";
	$count = (string)$count;
	$char = (int)$count[strlen($count)-1];
	if ($char == 1)
		$word = $ending1;
	elseif ($char > 1 && $char < 5)
		$word = $ending2;
	elseif ($char >= 5 || $char == 0)
		$word = $ending3;
	
	// если число больше 10
	if (((int)$count)/10 > 1)
	{
		// работаем со строкой, т.к. $count может быть, например 112
		$char = (int)($count[strlen($count)-2].$count[strlen($count)-1]);
		if ($char > 10 && $char < 15)
			$word = $ending3;
	}
	
	return $with ? $count." ".$word : $word;	
}

?>